package com.database.mapper;


import com.database.character.Collect;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CollectMapper {

  //添加收藏
  @Insert("insert into collect(user_id, post_id) values (#{userId}, #{postId})")
  int addCollect(Collect collect);

  //取消收藏
  @Delete("delete from collect where collect_id = #{collectId}")
  int deleteByCollectId(Integer collectId);

  //根据collectId查询收藏
  @Select("select * from collect where collect_id = #{collectId}")
  Collect getByCollectId(Integer collectId);

  //根据userId查询收藏
  @Select("select * from collect where user_id = #{userId}")
  List<Collect> getCollectByUid(Integer userId);

  //根据userId和postId查询收藏
  @Select("select * from collect where user_id = #{userId} and post_id = #{postId}")
  Collect getCollectByUidAndPid(Integer userId, Integer postId);

    //根据userId和postId删除收藏
    @Delete("delete from collect where user_id = #{userId} and post_id = #{postId}")
    int deleteByUidAndPid(Integer userId, Integer postId);

}
